﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class admin_pdfgl_qkylcs : System.Web.UI.Page
{
    GetPdf gp = new GetPdf();
    public int pagesize = 13;
    public int pages = 0;
    public int page = 1;
    public int prePage = 1;
    public int forPage = 1;
    public int dataTotal = 0;
    public string page_url;
    public bool bl = false;
    DataTable dt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin_id"] == null)
        {
            Response.Redirect("admin_logout.aspx");
            return;
        }
        if (!IsPostBack)
        {
            if (Request["page"] != null)
            {
                string p = Request["page"];
                page = int.Parse(p);
            }
            else
            {
                page = 1;
            }
            ViewState.Add("page", page);
            page_url = Request.Url.ToString().Split('?')[0];
            controlRepeater();
        }
    }
    private void controlRepeater()
    {
        if (ViewState["page"] != null)
        {
            page = (int)ViewState["page"];
        }
        DataTable table1 = gp.SelectAllPDF();
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = table1.DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = pagesize;
        pages = pds.PageCount;
        dataTotal = table1.Rows.Count;
        page = page < 1 ? 1 : page;
        page = page > pages ? pages : page;
        forPage = page + 1;
        prePage = page - 1;
        pds.CurrentPageIndex = page - 1;
        this.repeater1.DataSource = pds;
        this.repeater1.DataBind();
    }
    protected void rpt_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);
        switch (e.CommandName)
        {
            case "del":
                bl = false;
                bl = gp.ClearViewnum(id); 
                if (bl)
                {
                    this.lbMsg.Text = "操作成功";
                    controlRepeater();
                }
                else
                {
                    this.lbMsg.Text = "操作失败";
                    controlRepeater();
                }

                break;

            default:
                break;
        }

    }
    protected string checkout(bool bl)
    {
        if (bl)
        {
            return "是";
        }
        else
        {
            return "否";
        }
    }
    protected void button1_Click(object sender, EventArgs e)
    {
        bl = false;
        bl = gp.ClearAllViewnum();
        if (bl)
        {
            this.lbMsg.Text = "全部清空操作成功";
            controlRepeater();
        }
        else
        {
            this.lbMsg.Text = "全部清空操作失败";
            controlRepeater();
        }

    }
}
